package com.feihao.zhou.mapper;

import com.feihao.zhou.bean.Card;
import com.feihao.zhou.bean.Classes;
import com.feihao.zhou.bean.Person;
import com.feihao.zhou.bean.Student_Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ManyTableSelect {
    //一对一： card 对应 person

    @Select("select * from card")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "number", property = "number"),

            @Result(
                    property = "person", javaType = Person.class,
                    column = "pid",
                    one = @One(select = "com.feihao.zhou.otherMappers.PersonMapper.selectPerson")
            )
    })
    List<Card> selectAllCard();


    //一堆多：classes班级对应多个学生：

    @Select("select * from classes")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),

            @Result(
                    property = "students", javaType = List.class,
                    column = "id",
                    many = @Many(select = "com.feihao.zhou.otherMappers.StudentMapper.selectStudent")
            )
    })
    List<Classes> selectAllClasses();

    //多对多：学生有多个课程   ， 课程被多个学生选修

    @Select("select * from student")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "age", property = "age"),
            @Result(column = "cid", property = "cid"),

            @Result(
                    property = "course", javaType = List.class,
                    column = "cid",
                    many = @Many(select = "com.feihao.zhou.otherMappers.CourseMapper.selectCourse")
            )
    })
    List<Student_Course> selectAllStudent_Course();

}
